import { } from '@/services/ant-design-pro/api';
import { getting } from '@/services/ant-design-pro/setting';
import { SettingData } from '@/types/modules/setting';
import { Effect, Reducer } from 'umi';
export interface Setting {
    InitialValue: SettingData[]
}

export interface SettingType {
    namespace: 'settings';
    state: Setting;
    effects: {
        getting: Effect
    };
    reducers: {
        save: Reducer<Setting>
    };
}

const IndexModel: SettingType = {
    namespace: 'settings',
    state: {
        InitialValue: []
    },
    effects: {
        // 初始值
        *getting({ payload }, { call, put }) {
            const result = yield call(getting, payload);
            if (result.data) {
                yield put({
                    type: "save",
                    payload: {
                        InitialValue: result.data,
                    }
                })
            }
        }
    },
    reducers: {
        save(state, action) {
            return {
                ...state,
                ...action.payload,
            };
        },
    },
};

export default IndexModel;